//
//  NSString+Extension.h
//  meapp
//
//  Created by linjie on 16/2/18.
//  Copyright © 2016年 nd. All rights reserved.
//

#import "UIView+Extension.h"
#import "UIColor+Extension.h"
@implementation UIView (Extension)

- (void)setX:(CGFloat)x
{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}

- (void)setY:(CGFloat)y
{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}

- (CGFloat)x
{
    return self.frame.origin.x;
}

- (CGFloat)y
{
    return self.frame.origin.y;
}

-(CGFloat)maxX{
    return CGRectGetMaxX(self.frame);
}
-(CGFloat)maxY{
    return CGRectGetMaxY(self.frame);
}
- (void)setCenterX:(CGFloat)centerX
{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}

- (CGFloat)centerX
{
    return self.center.x;
}

- (void)setCenterY:(CGFloat)centerY
{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}

- (CGFloat)centerY
{
    return self.center.y;
}

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

- (CGFloat)height
{
    return self.frame.size.height;
}

- (CGFloat)width
{
    return self.frame.size.width;
}

- (void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}

- (CGSize)size
{
    return self.frame.size;
}

- (void)setOrigin:(CGPoint)origin
{
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}

- (CGPoint)origin
{
    return self.frame.origin;
}

- (void) setRoundStyle {
    self.clipsToBounds  = YES;
    self.layer.cornerRadius = self.height / 2.0;
}


-(void)setShadow{
    self.layer.shadowOffset = CGSizeMake(-1, 1);//shadowOffset阴影偏移,x向右偏移4，y向下偏移4，默认(0, -3),这个跟shadowRadius配合使用
    self.layer.shadowRadius = 2.0;//阴影半径
    self.layer.shadowColor = [UIColor blackColor].CGColor;
    self.layer.shadowOpacity = 0.4;//透明度
    [self.layer setCornerRadius:3];
    
}


-(void)setCellShadow:(long)height width:(long)width {
    UIImageView *bg = [[UIImageView alloc]init];
    bg.width =width - 16 ;
    bg.height = height  - 12;
    bg.x = 8 ;
    bg.y = 5 ;
    bg.backgroundColor = [UIColor whiteColor];
    [bg setShadow];
    [self addSubview:bg];
    [self sendSubviewToBack:bg];
}

-(void)setBorder:(float)borderWidth  cornerRadius:(float)cornerRadius{
    if (borderWidth != 0) {
        self.layer.borderWidth= borderWidth;
//        self.layer.borderColor= [UIColor colorWithHexString:@"#f4f4f4"].CGColor;
        self.layer.borderColor= [UIColor colorWithHexString:@"#dddddd"].CGColor;
    }
    if (cornerRadius !=0) {
          self.layer.cornerRadius = cornerRadius;
    }
}

-(void)setBorder:(float)borderWidth  cornerRadius:(float)cornerRadius color:(UIColor*)color;
{
    if (borderWidth != 0) {
        self.layer.borderWidth= borderWidth;
        if (color) {
            self.layer.borderColor= color.CGColor ;
        }else {
           self.layer.borderColor= [UIColor colorWithHexString:@"#f4f4f4"].CGColor;
        }
    }
    if (cornerRadius !=0) {
        self.layer.cornerRadius = cornerRadius;
    }
}
-(void)addLabelToTop:(BOOL)isNeed{
    if (isNeed) {
        if (![self viewWithTag:101]) {
            UILabel *topLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 34, 14)];
            topLabel.text = @"十元";
            topLabel.textAlignment =NSTextAlignmentCenter ;
            topLabel.font = [UIFont systemFontOfSize:12];
            topLabel.textColor =[UIColor whiteColor];
            topLabel.tag = 101 ;
            topLabel.hidden = NO ;
            topLabel.backgroundColor = [UIColor colorWithHexString:@"#40E0D0"];
            [self addSubview:topLabel];
        }else {
            UILabel *topLabel = [self viewWithTag:101] ;
            topLabel.hidden =NO ;
        }
    }else {
        if ([self viewWithTag:101]) {
            UILabel *topLabel = [self viewWithTag:101];
            topLabel.hidden = YES ;
            [topLabel removeFromSuperview];
        }
    }
}
@end
